package br.ufmg.ubicomp.droidguide.eventservice.notification;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;

public class NotificationBucket {

	List<DGNotification> notifications = new ArrayList<DGNotification>();
	List<String> alerts = new ArrayList<String>();
	private static final boolean showAppNotifications = true;
	
	private static NotificationBucket theBucket;
	
	private NotificationBucket()
	{		
	}
	
	public static NotificationBucket getInstance()
	{
		if (theBucket == null)
		{
			theBucket = new NotificationBucket();
		}
		return theBucket;
	}
	
	public void clear()
	{
		notifications.clear();
	}
	
	public void add(DGNotification not)
	{
		notifications.add(not);
	}
	
	public void addAlert(String msg)
	{
		alerts.add(msg);
	}
	
	public List<String> getAlerts()
	{
		return alerts;
	}
	
	public void addNotification(DGNotificationType type, long time, String text, String origin, Level level)
	{
		notifications.add(new DGNotification(type, time, text, origin, level));
	}
	
	public List<DGNotification> getNotifications()
	{
		return notifications;
	}
	
	public List<String> getNotificationsList()
	{
		List<String> list = new ArrayList<String>();
		for (DGNotification n: notifications)
		{
			// if we are not supposed to show App notifications and this notification is of type app
			if (!showAppNotifications && isNotificationOfTypeApplication(n))
			{
			} else
			{
				list.add(n.toString());
			}
		}
		return list;
	}

	private boolean isNotificationOfTypeApplication(DGNotification n) {
		return n.getType().equals(DGNotificationType.APPLICATION);
	}
}
